package org.itcast.adi.planinfo.execption;

import lombok.extern.slf4j.Slf4j;
import org.itcast.adi.planinfo.entity.ResultBean;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@ResponseBody
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(RuntimeException.class)
    public ResultBean exceptionHandler() {
        return ResultBean.error();
    }
    @Order(1)
    @ExceptionHandler(value = CustomException.class)
    public ResultBean customExceptionHandler(CustomException e) {
        log.error("错误原因为："+e.getMessage());
        return ResultBean.errorException(e.getCode(),e.getMessage());
    }
}
